home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacGofer 0.22d / MacGofer Sources / mac_scrap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-06  |  2.8 KB  |  128 lines  |  [TEXT/MPS ]

  1. /*****************************************************************************
  2.  
  3.   mac_scrap.c:  Copyright (c) Kevin Hammond 1993.   All rights reserved.
  4.   
  5.   Scrap Handling.
  6.    
  7.   This file contains routines to show/hide the clipboard,
  8.   and load the scrap from the TE private scrap or vice-versa
  9.   as necessary.
  10.    
  11. *****************************************************************************/
  12.  
  13.  
  14. #pragma segment Scrap
  15.  
  16. #include "mac.h"
  17.  
  18. Boolean scrapVisible = FALSE,            /* Whether the scrap is visible */
  19.         copyscrap = FALSE;            /* Set when the scrap must be copied */
  20.  
  21.  
  22. /*
  23.   Show or hide the clipboard.
  24. */
  25.  
  26.  
  27. showhideclipboard()
  28. {
  29.   if(!scrapVisible)
  30.     {
  31.       ShowWindow(WINDOW(scrap));
  32.       SelectWindow(WINDOW(scrap));
  33.       setitem(Menu_Edit,MItem_Show_Clipboard,"Hide Clipboard");
  34.     }
  35.   else
  36.     {
  37.       HideWindow(WINDOW(scrap));
  38.       setitem(Menu_Edit,MItem_Show_Clipboard,"Show Clipboard");
  39.     }
  40.   scrapVisible = !scrapVisible;
  41. }
  42.  
  43.  
  44. /*
  45.     Load the clipboard scrap from the actual scrap record.
  46. */
  47.  
  48.  
  49. long scrapTextLength = 0;
  50.  
  51. loadscrap()
  52. {
  53.   static short lastscrapcount = 0;
  54.   short newscrapcount;
  55.  
  56.   TEHandle scrapTE;
  57.   Handle scrapText;
  58.   
  59.   static Boolean scrapError = FALSE;
  60.  
  61.   long dummyOffset = 0;
  62.  
  63.   /* See if the scrap has changed */
  64.   newscrapcount = InfoScrap()->scrapCount;
  65.   if (newscrapcount == lastscrapcount)
  66.     return;
  67.  
  68.   /* If so, remember the scrapCount and get a handle to its text */
  69.   lastscrapcount = newscrapcount;
  70.   scrapTE = TEHANDLE(scrap);
  71.   scrapText = NewHandle(0);
  72.   scrapTextLength = GetScrap(scrapText,'TEXT',&dummyOffset);
  73.   
  74.   if(scrapTextLength > 32767)
  75.     {
  76.       /* Don't give more than one error for the same scrap overflow */
  77.       if(!scrapError)
  78.         {
  79.           Error("","Clipboard contents too large for Gofer to handle");
  80.           scrapError = TRUE;
  81.     }
  82.     }
  83.   else
  84.     {
  85.       scrapError = FALSE;
  86.       /* Now plug the handle into the scrap's TE record and notify TE */
  87.       DisposeHandle((**scrapTE).hText);
  88.       (**scrapTE).hText = scrapText;
  89.       TECalText(scrapTE);
  90.     
  91.       AdjustScrollBars(scrap);
  92.       AdjustText(scrap);
  93.   
  94.       if(scrapVisible)
  95.         {
  96.           /* The window must be the current port for invalidation */
  97.           GrafPtr saveport;
  98.  
  99.           /* Invalidate the visible region here */
  100.           GetPort(&saveport);
  101.           SetPort(WINDOW(scrap));
  102.  
  103.           EraseRgn(WINDOW(scrap)->visRgn);
  104.           InvalRgn(WINDOW(scrap)->visRgn);
  105.  
  106.           SetPort(saveport);
  107.         }
  108.     }
  109. }
  110.  
  111.  
  112. doscrap()
  113. {
  114.   if(copyscrap)
  115.     {
  116.       long err;
  117.       if((err=ZeroScrap()) != noErr)
  118.         AbortErrorN("Unexpected result (%d) from ZeroScrap",err);
  119.       if((err=TEToScrap()) != noErr)
  120.         AbortErrorN("Unexpected result (%d) from TEToScrap",err);
  121.       else
  122.         {
  123.           loadscrap();
  124.           copyscrap = FALSE;
  125.     }
  126.     }
  127. }
  128.